//跳转到线路信息页面
var goLineInfo;
//跳转到车辆信息页面
var goCarInfo;
require(['topBar', 'layout', 'date', 'grid'], function () {
    //提交到后台参数
    var postData,
        $dialog,//查看弹出窗口
        $grid = $('#grid');//数据展示grid
    $('#top').topBar({
        left: [{
            type: 'filter-more',
            dateType:'custom',
            search: function () {
                if (getPostData()) {
                    $grid.grid('setGridParam', {
                        page: 1,
                        datatype: "json",
                        postData: postData
                    }).trigger("reloadGrid");
                }
            },
            item: [
                {
                    text: '时间快捷',
                    name1: 'beginTime',
                    name2: 'endTime',
                    type: 'dateLine'
                },
                {
                    text: '方向',
                    name: 'inoutType',
                    type: 'item-select',
                    data: [
                        {text: '全部', value: ''},
                        {text: '驶入', value: '1'},
                        {text: '驶出', value: '0'}
                    ]
                }
            ]
        }]
    });

    $('body').layout();

    $grid.grid({
        multiselect: false,
        url: "/electFencAlm/searchElectFencAlmPage.htm",
        colModel: [
            {name: "fencId", label: "fencId", hidden: true},
            {name: "fencCd", label: "fencCd", hidden: true},
            {name: "carId", label: "carId", hidden: true},
            {name: "lineId", label: "lineId", hidden: true},
            {name: "licPltNo", label: "车牌号",formatter: function (cellvalue,options,rowObject) {
            	return "<b><a href='javascript:void(0);' onclick='goCarInfo(\"" + rowObject.carId + "\")' class='text-link c-blue'>" + cellvalue + "</a></b>";
            }},
            {name: "carInCd", label: "车辆编号", width: 80},
            {name: "lineName", label: "运营线路",formatter: 'customCurrency',formatoptions:{
                redbtn:true,
                css:'text-link c-blue',
                clickFn:function(rowObject,cellvalue){
                	goLineInfo(rowObject.lineId);
                }
            }},
            {name: "organName", label: "所属机构"},
            {name: "fencName", label: "区域名称"},
            {name: "inoutType", label: "类型"},
            {name: "inoutTime", label: "发生时间"},
            {name: "inoutSpdOfMotVhi", label: "车速", align: "right"},
            {name: "inoutLgt", label: "INOUT_LGT", hidden: true},
            {name: "inoutLtt", label: "INOUT_LTT", hidden: true},
            {name: "inoutDrc", label: "INOUT_DRC", hidden: true},
            {
                name: "operate", width: 80, label: '操作', align: "center",
                formatter: 'operArea',
                formatoptions: [{
                    text: '查看',
                    css: 'operate-scan',
                    click: function (data) {
                        viewElectFencAlm();
                        getElectFencAlmInfo(data.fencId);
                        showCarInfo(data);
                    }
                }]
            }
        ]
    });

    //获取左侧选择的节点信息
    function getPostData() {
        var rcx = commonFun.getTreeCheckNodeToArgs();
        if (rcx) {
            postData = $.extend(rcx, $("#top").parent().getValues());
        }
        return rcx;
    }

    function getElectFencAlmInfo(fencId) {
        $.ajaxExt({
            url: "/electFencSet/getBaseElectFencById.htm",
            data: {"fencId": fencId}
        }).done(function (data) {
            $dialog.dialog('exec', 'showSingleElectFencMap', data);
        });
    }

    function showCarInfo(data){										// 在这里构造车辆数据的数组
        var obj = new Object();  										//车辆数据
        obj.licPltNo = data.licPltNo;	 										//车牌号
        obj.driverName = ""; 									//驾驶员
        obj.loLgt = data.inoutLgt; 											//经度
        obj.loLtt = data.inoutLtt; 											//纬度
        obj.direction = data.inoutDrc; 										//异常类型 字符串表示
        obj.inoutTime = data.inoutTime;                              //发生时间
        obj.speed = data.inoutSpdOfMotVhi;                    //发生车速
        $dialog.dialog('exec', 'showMapLocation', obj);
    }

    //在地图上查看对应的电子围栏
    function viewElectFencAlm() {
        if (!$dialog) {
            $dialog = $('<div>').dialog({
                title: '查看电子围栏',
                url: './service/report/ElectFencMap.htm',
                height: $(window.parent).height() * 0.8,
                width: $(window.parent).width() * 0.8,
                close: function () {
                    $(this).dialog('exec', 'clear');
                }
            });
        }
        $dialog.dialog('open');
    }
    
  //跳转到车辆信息页面
    goCarInfo = function(carId){
    	var data = {};
    	data.carId = carId;
    	$.openTab('6bad880fef164ec6adaea7b18420eb6e','showCarInfo',[data]);
    }
    //跳转到线路信息页面
    goLineInfo = function(lineId){
    	var data = {};
    	data.lineId = lineId;
    	$.openTab('4db17f8a322b4749a61eb2f8a12023ae','showLineInfo',[data]);
    }
});